﻿if (typeof Axis == "undefined") Axis = {};
if (typeof Axis.View == "undefined") Axis.View = {};
if (typeof Axis.View.Member == "undefined") Axis.View.Member = {};
Axis.View.Member.PrivateBox = {
    Init: function () {
        var thisObj = this;
        setTimeout(function () {
            thisObj.GetProjectInfo();
        }, 1000);
    },
    GetProjectInfo: function () {
        var $tmp = $('<div></div>');
        $tmp.load('../template/profile_project_info.txt', function () {
            $.Ajax({
                url: "../Project/Service/ProjectService.asmx/GetProjectByMember",
                type: 'POST',
                data: {},
                beforeSend: function () {
                },
                success: function (data, textStatus, xhr) {
                    var ret = "";
                    if (data) {
                        data = $.findInXml(data);
                        data = eval("(" + data + ")");
                        if (data) {
                            console.log(data);
                            $.each(data, function (index, item) {
                                var template = $tmp.html();
                                var typeName = "Dự án";
                              //  console.log(item.Type, (item.Type == "1"));
                                if (item.Type == "1")
                                    typeName = "Bình chọn";
                                var UserResponseDateTime = item.UserResponseDateTime;
                                if (UserResponseDateTime) {
                                    var UserResponseDateTime = new Date(parseInt(UserResponseDateTime.replace("/Date(", "").replace(")/", ""), 10));
                                    UserResponseDateTime = $.CFormat.FormatDate(UserResponseDateTime, "d", "vi-VN");
                                }
                                template = template.replace("[ProjectID]", item.ID);
                                template = template.replace("[TypeName]", typeName);
                                template = template.replace("[Type]", item.Type);
                                template = template.replace("[ProjectName]", item.Name);
                                template = template.replace("[Mark]", item.Mark);
                                template = template.replace("[ProjectPercent]", item.UserResponseCompleted ? "100%" : "50%");
                                template = template.replace("[ProjectDate]", UserResponseDateTime);
                                ret += template;
                            });

                        }
                    }
                    $("#project-list-info ul").html(ret);
                },
                error: function (xhr, textStatus, errorThrown) { }
            });
        });
    }

};
$(function () {


    Axis.View.Member.PrivateBox.Init();
});